<?php

class AdminModule extends WebModule
{
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'admin.models.*',
			'admin.components.*',
		));

		// this sets default settings for admin module
        $this->setComponents(array(
            'errorHandler' => array(// set error handler specificly for this module
                'errorAction' => "/{$this->name}/{$this->defaultController}/error"
            ),
            'user' => array( // set user and authentication options
                'class'=>'WebUser',
                'allowAutoLogin' => true,
                'loginUrl' => array("/{$this->name}/{$this->defaultController}/login"),
                'logoutUrl' => array("/{$this->name}/{$this->defaultController}/logout"), 
                'stateKeyPrefix' => "_{$this->id}",
            ),
        ));

		Yii::app()->theme = "admin";

		parent::init();
	}

	public function getSideMenu($type)
	{
		$sideMenu = array();
		switch ($type) {
			case 'user':
				$sideMenu = array(
                    array('label'=>'Manage User', 'url'=>array('/admin/user')),
					array('label'=>'Export User (Excel)', 'url'=>array('/admin/user/exportExcel')),
                    array('label'=>'<hr />'),
                    array('label'=>'Add Winner', 'url'=>array('/admin/winner/create')),
                    array('label'=>'Manage Winner', 'url'=>array('/admin/winner')),
                    array('label'=>'<hr />'),
                    array('label'=>'Sync Tool', 'url'=>array('/admin/user/synctool')),
				);
				break;

			default:
				break;
		}

		return $sideMenu;
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			// this method is called before any module controller action is performed
			// you may place customized code here
			return true;
		}
		else
			return false;
	}
}
